<!DOCTYPE html>


<html lang="zh-CN">


<head>
  <meta charset="utf-8" />
    
  <meta name="description" content="迎着朝阳的博客" />
  
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
  <title>
    常用docker命令 |  迎着朝阳
  </title>
  <meta name="generator" content="hexo-theme-ayer">
  
  <link rel="shortcut icon" href="https://dxysun.com/static/yan.png" />
  
  
<link rel="stylesheet" href="/dist/main.css">

  
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/Shen-Yu/cdn/css/remixicon.min.css">

  
<link rel="stylesheet" href="/css/custom.css">

  
  
<script src="https://cdn.jsdelivr.net/npm/pace-js@1.0.2/pace.min.js"></script>

  
  

  
<script>
var _hmt = _hmt || [];
(function() {
	var hm = document.createElement("script");
	hm.src = "https://hm.baidu.com/hm.js?aa994a8d65700b8835787dd39d079d7e";
	var s = document.getElementsByTagName("script")[0]; 
	s.parentNode.insertBefore(hm, s);
})();
</script>


</head>

</html>

<body>
  <div id="app">
    
      
    <main class="content on">
      <section class="outer">
  <article
  id="post-dockerForCommmand"
  class="article article-type-post"
  itemscope
  itemprop="blogPost"
  data-scroll-reveal
>
  <div class="article-inner">
    
    <header class="article-header">
       
<h1 class="article-title sea-center" style="border-left:0" itemprop="name">
  常用docker命令
</h1>
 

    </header>
     
    <div class="article-meta">
      <a href="/2018/07/10/dockerForCommmand/" class="article-date">
  <time datetime="2018-07-10T02:53:24.000Z" itemprop="datePublished">2018-07-10</time>
</a>   
<div class="word_count">
    <span class="post-time">
        <span class="post-meta-item-icon">
            <i class="ri-quill-pen-line"></i>
            <span class="post-meta-item-text"> 字数统计:</span>
            <span class="post-count">3.1k</span>
        </span>
    </span>

    <span class="post-time">
        &nbsp; | &nbsp;
        <span class="post-meta-item-icon">
            <i class="ri-book-open-line"></i>
            <span class="post-meta-item-text"> 阅读时长≈</span>
            <span class="post-count">15 分钟</span>
        </span>
    </span>
</div>
 
    </div>
      
    <div class="tocbot"></div>




  
    <div class="article-entry" itemprop="articleBody">
       
  <p>最近要用docker，在这里记录docker常用命令</p>
<a id="more"></a>

<h1 id="启动-停止-重启-杀掉容器"><a href="#启动-停止-重启-杀掉容器" class="headerlink" title="启动/停止/重启/杀掉容器"></a>启动/停止/重启/杀掉容器</h1><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker start&#x2F;stop&#x2F;restart&#x2F;kill 容器name或容器id</span><br></pre></td></tr></table></figure>
<p>示例</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">[root@docker ~]# docker start myweb</span><br><span class="line">[root@docker ~]# docker stop myweb</span><br><span class="line">[root@docker ~]# docker restart myweb</span><br><span class="line">[root@docker ~]# docker kill -s kill myweb</span><br><span class="line">参数 -s  #向容器发送信号</span><br></pre></td></tr></table></figure>

<h1 id="创建并启动一个新的容器"><a href="#创建并启动一个新的容器" class="headerlink" title="创建并启动一个新的容器"></a>创建并启动一个新的容器</h1><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker run</span><br></pre></td></tr></table></figure>
<blockquote>
<p>常用参数<br>-d             #后台运行容器，并返回容器ID<br>-i              #以交互式模式运行容器，常与-t参数同时使用<br>-t              #给容器重新分配一个伪终端，常与-i参数同时使用<br>–name     #给容器指定一个名称<br>-m            #指定容器使用内存的最大值<br>–net        #指定容器使用的网络类型<br>–link        #链接到另一个容器</p>
</blockquote>
<p>示例</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">[root@docker ~]# docker run -d --name nginx nginx:latest</span><br><span class="line">#后台启动并运行一个名为nginx的容器，运行前它会自动去docker镜像站点下载最新的镜像文件</span><br><span class="line">[root@docker ~]# docker run -d -P 80:80 nginx:latest</span><br><span class="line">#后台启动并运名为nginx的容器，然后将容器的80端口映射到物理机的80端口</span><br><span class="line">[root@docker ~]# docker run -d -v &#x2F;docker&#x2F;data:&#x2F;docker&#x2F;data -P 80:80 nginx:latest</span><br><span class="line">#后台启动并运名为nginx的容器，然后将容器的80端口映射到物理机的80端口,并且将物理机的&#x2F;docker&#x2F;data目录映射到容器的&#x2F;docker&#x2F;data</span><br><span class="line">[root@docker ~]# docker run -it  nginx:latest &#x2F;bin&#x2F;bash</span><br><span class="line">#以交互式模式运行容器，然后在容器内执行&#x2F;bin&#x2F;bash命令</span><br></pre></td></tr></table></figure>

<h1 id="删除容器"><a href="#删除容器" class="headerlink" title="删除容器"></a>删除容器</h1><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker rm 容器id或容器name</span><br></pre></td></tr></table></figure>
<blockquote>
<p>常用参数<br>-f     #强制删除一个运行中的容器<br>-l     #删除指定的链接<br>-v     #删除与容器关联和卷</p>
</blockquote>
<p>示例</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">[root@docker ~]# docker rm -f mydocker</span><br><span class="line">#强制删除容器mydocker</span><br><span class="line">[root@docker ~]# docker rm -f dockerA dockerB</span><br><span class="line">#强制删除容器dockerA，dockerB</span><br><span class="line">[root@docker ~]# docker rm -v mydocker</span><br><span class="line">#删除容器，并删除容器挂载的数据卷</span><br></pre></td></tr></table></figure>

<h1 id="创建一个新的容器但不启动它"><a href="#创建一个新的容器但不启动它" class="headerlink" title="创建一个新的容器但不启动它"></a>创建一个新的容器但不启动它</h1><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker create</span><br></pre></td></tr></table></figure>
<p>示例</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">[root@docker ~]# docker create --name myserver nginx:latest</span><br><span class="line">09b93464c2f75b7b69f83d56a9cfc23ceb50a48a9db7652ee4c27e3e2cb1961f</span><br><span class="line">#创建一个名为myserver的容器</span><br></pre></td></tr></table></figure>
<h1 id="在运行的容器中执行命令"><a href="#在运行的容器中执行命令" class="headerlink" title="在运行的容器中执行命令"></a>在运行的容器中执行命令</h1><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker exec</span><br></pre></td></tr></table></figure>
<blockquote>
<p>常用参数<br>-d      #在后台运行<br>-i      #保持STDIN打开<br>-t      #分配一个伪终端</p>
</blockquote>
<p>示例</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">[root@docker ~]# docker exec -it mydocker &#x2F;bin&#x2F;sh &#x2F;server&#x2F;scripts&#x2F;docker.sh</span><br><span class="line">hello world!!!!!!!!!!</span><br><span class="line">#以交互模式执行容器中的&#x2F;server&#x2F;scripts&#x2F;docker.sh脚本</span><br><span class="line">[root@docker ~]# docker exec -it mydocker &#x2F;bin&#x2F;sh </span><br><span class="line">root@b1a0703e41e7:&#x2F;#</span><br><span class="line">#以交互模式给容器分配一个伪终端连接</span><br></pre></td></tr></table></figure>

<h1 id="列出容器（正在运行）"><a href="#列出容器（正在运行）" class="headerlink" title="列出容器（正在运行）"></a>列出容器（正在运行）</h1><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker ps</span><br></pre></td></tr></table></figure>
<blockquote>
<p>常用参数<br>-a      #列出所有容器包括停止的<br>-f      #根据条件过滤显示内容<br>-l      #列出最近创建的容器<br>-n      #列出最近创建的N个容器，N为数字<br>-q      #只显示容器ID<br>-s      #显示总文件大小</p>
</blockquote>
<p>示例</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">[root@docker ~]# docker ps</span><br><span class="line">CONTAINER ID  IMAGE            COMMAND                  CREATED       STATUS       PORTS                                            NAMES</span><br><span class="line">bd96d72ed9c7  google&#x2F;cadvisor  &quot;&#x2F;usr&#x2F;bin&#x2F;cadvisor...&quot;   47 hours ago  Up 47 hours  0.0.0.0:8082-&gt;8080&#x2F;tcp                           cadvisor</span><br><span class="line">665563143eb7  grafana&#x2F;grafana  &quot;&#x2F;run.sh&quot;                2 days ago    Up 2 days    0.0.0.0:3000-&gt;3000&#x2F;tcp                           grafana</span><br><span class="line">f2304dad5855  tutum&#x2F;influxdb   &quot;&#x2F;run.sh&quot;                2 days ago    Up 2 days    0.0.0.0:8083-&gt;8083&#x2F;tcp, 0.0.0.0:8086-&gt;8086&#x2F;tcp   influxdb</span><br><span class="line">#列出正在运行的容器</span><br><span class="line">[root@docker ~]# docker ps -n 2</span><br><span class="line">CONTAINER ID   IMAGE               COMMAND                  CREATED       STATUS       PORTS                    NAMES</span><br><span class="line">bd96d72ed9c7   google&#x2F;cadvisor     &quot;&#x2F;usr&#x2F;bin&#x2F;cadvisor...&quot;   47 hours ago  Up 47 hours  0.0.0.0:8082-&gt;8080&#x2F;tcp   cadvisor</span><br><span class="line">665563143eb7   grafana&#x2F;grafana     &quot;&#x2F;run.sh&quot;                2 days ago    Up 2 days    0.0.0.0:3000-&gt;3000&#x2F;tcp   grafana</span><br><span class="line">#列出最近创建的2个容器</span><br><span class="line">[root@docker ~]# docker ps -a -q</span><br><span class="line">bd96d72ed9c7</span><br><span class="line">665563143eb7</span><br><span class="line">f2304dad5855</span><br><span class="line">9921d2660307</span><br><span class="line">#显示所有容器的ID</span><br></pre></td></tr></table></figure>

<h1 id="获取容器的元数据"><a href="#获取容器的元数据" class="headerlink" title="获取容器的元数据"></a>获取容器的元数据</h1><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker inspect</span><br></pre></td></tr></table></figure>
<blockquote>
<p>常用参数<br>-f        #指定返回值格式或模板文件<br>-s        #显示总文件大小<br>–type    #为指定类型返回JSON</p>
</blockquote>
<p>示例</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br></pre></td><td class="code"><pre><span class="line">[root@docker ~]# docker inspect bd96d72ed9c7</span><br><span class="line">[</span><br><span class="line">    &#123;</span><br><span class="line">        &quot;Id&quot;: &quot;bd96d72ed9c713591ba8db0ed4c0ae2689188255da71033c7bced6bb34aa8542&quot;,</span><br><span class="line">        &quot;Created&quot;: &quot;2018-05-23T09:22:10.633809699Z&quot;,</span><br><span class="line">        &quot;Path&quot;: &quot;&#x2F;usr&#x2F;bin&#x2F;cadvisor&quot;,</span><br><span class="line">        &quot;Args&quot;: [</span><br><span class="line">            &quot;-logtostderr&quot;,</span><br><span class="line">            &quot;-storage_driver&#x3D;influxdb&quot;,</span><br><span class="line">            &quot;-storage_driver_db&#x3D;cadvisor&quot;,</span><br><span class="line">            &quot;-storage_driver_host&#x3D;192.168.3.82:8086&quot;</span><br><span class="line">        ],</span><br><span class="line">        &quot;State&quot;: &#123;</span><br><span class="line">            &quot;Status&quot;: &quot;running&quot;,</span><br><span class="line">            &quot;Running&quot;: true,</span><br><span class="line">            &quot;Paused&quot;: false,</span><br><span class="line">            &quot;Restarting&quot;: false,</span><br><span class="line">            &quot;OOMKilled&quot;: false,</span><br><span class="line">            &quot;Dead&quot;: false,</span><br><span class="line">            &quot;Pid&quot;: 17589,</span><br><span class="line">            &quot;ExitCode&quot;: 0,</span><br><span class="line">            &quot;Error&quot;: &quot;&quot;,</span><br><span class="line">            &quot;StartedAt&quot;: &quot;2018-05-23T09:22:10.769771142Z&quot;,</span><br><span class="line">            &quot;FinishedAt&quot;: &quot;0001-01-01T00:00:00Z&quot;</span><br><span class="line">        &#125;,</span><br><span class="line">        &quot;Image&quot;: &quot;sha256:75f88e3ec333cbb410297e4f40297ac615e076b4a50aeeae49f287093ff01ab1&quot;,</span><br><span class="line">        &quot;ResolvConfPath&quot;: &quot;&#x2F;var&#x2F;lib&#x2F;docker&#x2F;containers&#x2F;bd96d72ed9c713591ba8db0ed4c0ae2689188255da71033c7bced6bb34aa8542&#x2F;resolv.conf&quot;,</span><br><span class="line">        &quot;HostnamePath&quot;: &quot;&#x2F;var&#x2F;lib&#x2F;docker&#x2F;containers&#x2F;bd96d72ed9c713591ba8db0ed4c0ae2689188255da71033c7bced6bb34aa8542&#x2F;hostname&quot;,</span><br><span class="line">        &quot;HostsPath&quot;: &quot;&#x2F;var&#x2F;lib&#x2F;docker&#x2F;containers&#x2F;bd96d72ed9c713591ba8db0ed4c0ae2689188255da71033c7bced6bb34aa8542&#x2F;hosts&quot;,</span><br><span class="line">        &quot;LogPath&quot;: &quot;&quot;,</span><br><span class="line">        &quot;Name&quot;: &quot;&#x2F;cadvisor&quot;,</span><br><span class="line">        &quot;RestartCount&quot;: 0,</span><br><span class="line">        &quot;Driver&quot;: &quot;overlay2&quot;,</span><br><span class="line">        &quot;MountLabel&quot;: &quot;&quot;,</span><br><span class="line">        &quot;ProcessLabel&quot;: &quot;&quot;,</span><br><span class="line">        &quot;AppArmorProfile&quot;: &quot;&quot;,</span><br><span class="line">        &quot;ExecIDs&quot;: null,</span><br><span class="line">        &quot;HostConfig&quot;: &#123;</span><br><span class="line">            &quot;Binds&quot;: [</span><br><span class="line">                &quot;&#x2F;:&#x2F;rootfs,ro&quot;,</span><br><span class="line">                &quot;&#x2F;var&#x2F;run:&#x2F;var&#x2F;run&quot;,</span><br><span class="line">-------------------------------------------省略部分内容</span><br><span class="line">#获取容器ID为bd96d72ed9c7的元数据信息</span><br><span class="line">[root@docker ~]# docker inspect --format&#x3D;&#39;&#123;&#123;range .NetworkSettings.Networks&#125;&#125;&#123;&#123;.IPAddress&#125;&#125;&#123;&#123;end&#125;&#125;&#39; cadvisor</span><br><span class="line">172.17.0.3</span><br><span class="line">[root@docker ~]# docker inspect --format&#x3D;&#39;&#123;&#123;range .NetworkSettings.Networks&#125;&#125;&#123;&#123;.IPAddress&#125;&#125;&#123;&#123;end&#125;&#125;&#39; influxdb</span><br><span class="line">172.17.0.2</span><br><span class="line">#获取容器名为influxdb\cadvisor的IP地址</span><br></pre></td></tr></table></figure>

<h1 id="获取容器的日志"><a href="#获取容器的日志" class="headerlink" title="获取容器的日志"></a>获取容器的日志</h1><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker logs</span><br></pre></td></tr></table></figure>
<blockquote>
<p>常用参数<br>-f        #跟踪日志输出<br>-t        #显示时间戳<br>–tail    #只显示最新n条容器日志<br>–since   #显示某个开始时间的所有日志</p>
</blockquote>
<p>实例操作如下：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">[root@docker ~]# docker logs -f cadvisor</span><br><span class="line">I0523 09:22:10.794233       1 storagedriver.go:48] Using backend storage type &quot;influxdb&quot;</span><br><span class="line">I0523 09:22:10.794295       1 storagedriver.go:50] Caching stats in memory for 2m0s</span><br><span class="line">I0523 09:22:10.794551       1 manager.go:151] cAdvisor running in container: &quot;&#x2F;sys&#x2F;fs&#x2F;cgroup&#x2F;cpuacct,cpu&quot;</span><br><span class="line">I0523 09:22:10.810585       1 fs.go:139] Filesystem UUIDs: map[]</span><br><span class="line">#跟踪查看容器cadvisor的日志</span><br></pre></td></tr></table></figure>

<h1 id="显示指定容器的端口映射"><a href="#显示指定容器的端口映射" class="headerlink" title="显示指定容器的端口映射"></a>显示指定容器的端口映射</h1><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker port</span><br></pre></td></tr></table></figure>
<p>示例</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">[root@docker ~]# docker port cadvisor</span><br><span class="line">8080&#x2F;tcp -&gt; 0.0.0.0:8082</span><br><span class="line">#显示cadvisor容器的端口映射信息</span><br></pre></td></tr></table></figure>

<h1 id="用已存在的容器重新创建一个新的镜像"><a href="#用已存在的容器重新创建一个新的镜像" class="headerlink" title="用已存在的容器重新创建一个新的镜像"></a>用已存在的容器重新创建一个新的镜像</h1><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker commit</span><br></pre></td></tr></table></figure>
<blockquote>
<p>常用参数<br>-a      #提交的镜像作者<br>-c      #使用Dockerfile指令来创建镜像<br>-m      #提交时附上说明文字<br>-p      #在commit时，将容器暂停</p>
</blockquote>
<p>示例：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">[root@docker ~]# docker commit -a &quot;mingongge&quot; -m &quot;add a new images&quot; bd96d72ed9c7  newdocker_images:v1.0.0</span><br><span class="line">sha256:20ee805752cb7cae660fbae89d7c6ea4a9c6372f16a6cb079ecf6c79f87ed8c9</span><br><span class="line">[root@docker ~]# docker images</span><br><span class="line">REPOSITORY          TAG       IMAGE ID       CREATED        SIZE</span><br><span class="line">newdocker_images    v1.0.0    20ee805752cb   7 seconds ago  62.2 MB</span><br><span class="line">#将容器bd96d72ed9c7重新生成一个新的镜像名为newdocker_images</span><br></pre></td></tr></table></figure>

<h1 id="容器与物理主机之间拷贝文件"><a href="#容器与物理主机之间拷贝文件" class="headerlink" title="容器与物理主机之间拷贝文件"></a>容器与物理主机之间拷贝文件</h1><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker cp</span><br></pre></td></tr></table></figure>
<p>示例</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">[root@docker ~]# docker cp &#x2F;data&#x2F;index.html bd96d72ed9c7:&#x2F;web&#x2F;</span><br><span class="line">#将物理主机中的&#x2F;data&#x2F;index.html拷贝到容器bd96d72ed9c7:&#x2F;web&#x2F;目录下</span><br><span class="line">[root@docker ~]# docker cp &#x2F;data&#x2F;index.html bd96d72ed9c7:&#x2F;web&#x2F;index.php</span><br><span class="line">#将物理主机中的&#x2F;data&#x2F;index.html拷贝到容器bd96d72ed9c7:&#x2F;web&#x2F;目录下并改名为index.php</span><br><span class="line">[root@docker ~]# docker cp  bd96d72ed9c7:&#x2F;web  &#x2F;data&#x2F;</span><br><span class="line">#拷贝容器bd96d72ed9c7:&#x2F;web&#x2F;目录到物理主机中的&#x2F;data&#x2F;目录下</span><br></pre></td></tr></table></figure>

<h1 id="登录与登出容器镜像仓库"><a href="#登录与登出容器镜像仓库" class="headerlink" title="登录与登出容器镜像仓库"></a>登录与登出容器镜像仓库</h1><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">docker login       #登陆到一个Docker镜像仓库，如果未指定镜像仓库地址，默认为官方仓库 Docker Hub</span><br><span class="line">docker logout      #登出一个Docker镜像仓库，如果未指定镜像仓库地址，默认为官方仓库 Docker Hub</span><br></pre></td></tr></table></figure>
<blockquote>
<p>常用参数<br>-u      #登陆的用户名<br>-p      #登陆的密码</p>
</blockquote>
<p>示例</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">[root@docker ~]# docker login -u username -p password</span><br><span class="line">Login Succeeded</span><br><span class="line">[root@docker ~]# docker logout</span><br><span class="line">Removing login credentials for https:&#x2F;&#x2F;index.docker.io&#x2F;v1&#x2F;</span><br><span class="line">#登录与登出默认的容器镜像仓库</span><br></pre></td></tr></table></figure>

<h1 id="从镜像仓库中拉取或上传镜像"><a href="#从镜像仓库中拉取或上传镜像" class="headerlink" title="从镜像仓库中拉取或上传镜像"></a>从镜像仓库中拉取或上传镜像</h1><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">docker pull    #从镜像仓库中拉取或者更新指定镜像</span><br><span class="line">docker push    #将本地的镜像上传到镜像仓库,要先登陆到镜像仓库</span><br></pre></td></tr></table></figure>

<p>示例：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">[root@docker ~]# docker  pull  nginx</span><br><span class="line">Using default tag: latest</span><br><span class="line">Trying to pull repository docker.io&#x2F;library&#x2F;nginx ... </span><br><span class="line">latest: Pulling from docker.io&#x2F;library&#x2F;nginx</span><br><span class="line">f2aa67a397c4: Already exists </span><br><span class="line">3c091c23e29d: Pulling fs layer </span><br><span class="line">4a99993b8636: Pulling fs layer</span><br><span class="line">#从镜像仓库中拉取或者更新指定镜像，输出信息如上</span><br><span class="line">[root@docker ~]# docker push newdocker_images:v1.0.0</span><br><span class="line">#上传镜像到镜像仓库上</span><br></pre></td></tr></table></figure>

<h1 id="显示系统本地容器镜像文件"><a href="#显示系统本地容器镜像文件" class="headerlink" title="显示系统本地容器镜像文件"></a>显示系统本地容器镜像文件</h1><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker images</span><br></pre></td></tr></table></figure>
<blockquote>
<p>常用参数<br>-a                #列出所有的镜像（含中间映像层，默认，过滤掉中间映像层）；<br>–digests      #显示镜像的摘要信息；<br>-f                  #显示满足条件的镜像；<br>–format       #指定返回值的模板文件；<br>–no-trunc     #显示完整的镜像信息；<br>-q                 #只显示镜像ID。</p>
</blockquote>
<p>示例</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br></pre></td><td class="code"><pre><span class="line">[root@docker ~]# docker images</span><br><span class="line">REPOSITORY                                 TAG       IMAGE ID       CREATED         SIZE</span><br><span class="line">newdocker_images                           v1.0.0    20ee805752cb   28 minutes ago  62.2 MB</span><br><span class="line">docker.io&#x2F;grafana&#x2F;grafana                  latest    4700307f41f2   9 days ago      238 MB</span><br><span class="line">registry.jumpserver.org&#x2F;public&#x2F;guacamole   1.0.0     6300349f2642   2 months ago    1.23 GB</span><br><span class="line">docker.io&#x2F;google&#x2F;cadvisor                  latest    75f88e3ec333   5 months ago    62.2 MB</span><br><span class="line">docker.io&#x2F;tutum&#x2F;influxdb                   latest    c061e5808198   19 months ago   290 MB</span><br><span class="line">#列出本地所有的镜像</span><br><span class="line">[root@docker ~]# docker images -q</span><br><span class="line">20ee805752cb</span><br><span class="line">4700307f41f2</span><br><span class="line">6300349f2642</span><br><span class="line">75f88e3ec333</span><br><span class="line">c061e5808198</span><br><span class="line">#只显示容器ID</span><br><span class="line">[root@docker ~]# docker images --digests</span><br><span class="line">REPOSITORY                                 TAG      DIGEST                                                                    IMAGE ID        CREATED         SIZE</span><br><span class="line">newdocker_images                           v1.0.0   &lt;none&gt;                                                                    20ee805752cb    32 minutes ago  62.2 MB</span><br><span class="line">docker.io&#x2F;grafana&#x2F;grafana                  latest   sha256:364bec4a39ecbec744ea4270aae35f6554eb6f2047b3ee08f7b5f1134857c32c   4700307f41f2    9 days ago      238 MB</span><br><span class="line">registry.jumpserver.org&#x2F;public&#x2F;guacamole   1.0.0    sha256:ea862bb2e83b648701655c27900bca14b0ab7ab9d4572e716c25a816dc55307b   6300349f2642    2 months ago    1.23 GB</span><br><span class="line">docker.io&#x2F;google&#x2F;cadvisor                  latest   sha256:9e347affc725efd3bfe95aa69362cf833aa810f84e6cb9eed1cb65c35216632a   75f88e3ec333    5 months ago    62.2 MB</span><br><span class="line">docker.io&#x2F;tutum&#x2F;influxdb                   latest   sha256:5b7c5e318303ad059f3d1a73d084c12cb39ae4f35f7391b79b0ff2c0ba45304b   c061e5808198    19 months ago   290 MB</span><br><span class="line">[root@docker ~]# docker images --no-trunc                                                                                                     </span><br><span class="line">REPOSITORY                                 TAG      IMAGE ID                                                                  CREATED         SIZE</span><br><span class="line">newdocker_images                           v1.0.0   sha256:20ee805752cb7cae660fbae89d7c6ea4a9c6372f16a6cb079ecf6c79f87ed8c9   32 minutes ago  62.2 MB</span><br><span class="line">docker.io&#x2F;grafana&#x2F;grafana                  latest   sha256:4700307f41f249630f6d772638ad8d32c7d7e3ec86c324d449d5e21076991bb7   9 days ago      238 MB</span><br><span class="line">registry.jumpserver.org&#x2F;public&#x2F;guacamole   1.0.0    sha256:6300349f264218e783cd2bd6f7863d356ac8d5ac05a62584cb4680af7ebec292   2 months ago    1.23 GB</span><br><span class="line">docker.io&#x2F;google&#x2F;cadvisor                  latest   sha256:75f88e3ec333cbb410297e4f40297ac615e076b4a50aeeae49f287093ff01ab1   5 months ago    62.2 MB</span><br><span class="line">docker.io&#x2F;tutum&#x2F;influxdb                   latest   sha256:c061e580819875fad91910841fd3fc53893524bbb9326a68b2470861633aebb1   19 months ago   290 MB</span><br><span class="line">#可以对比下两个参数显示的不同信息</span><br></pre></td></tr></table></figure>

<h1 id="删除镜像"><a href="#删除镜像" class="headerlink" title="删除镜像"></a>删除镜像</h1><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker rmi</span><br></pre></td></tr></table></figure>
<blockquote>
<p>常用参数<br>-f      #强制删除</p>
</blockquote>
<h1 id="标记本地镜像"><a href="#标记本地镜像" class="headerlink" title="标记本地镜像"></a>标记本地镜像</h1><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker tag</span><br></pre></td></tr></table></figure>
<p>示例</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">[root@docker ~]# docker images</span><br><span class="line">REPOSITORY           TAG        IMAGE ID            CREATED             SIZE</span><br><span class="line">newdocker_images     v1.1.0     858cbd9ba687        39 seconds ago      62.2 MB</span><br><span class="line">[root@docker ~]# docker tag newdocker_images:v1.1.0 newdocker_images:v2</span><br><span class="line">[root@docker ~]# docker images</span><br><span class="line">REPOSITORY           TAG        IMAGE ID            CREATED             SIZE</span><br><span class="line">newdocker_images     v1.1.0     858cbd9ba687        4 minutes ago       62.2 MB</span><br><span class="line">newdocker_images     v2         858cbd9ba687        4 minutes ago       62.2 MB</span><br><span class="line">#从结果可以看出两个容器的ID是一样的，只是TAG改变了，类似于linux中文件与文件的硬链接一样，其两者的inode号相同。</span><br></pre></td></tr></table></figure>

<h1 id="使用Dockerfile创建镜像"><a href="#使用Dockerfile创建镜像" class="headerlink" title="使用Dockerfile创建镜像"></a>使用Dockerfile创建镜像</h1><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker build</span><br></pre></td></tr></table></figure>
<blockquote>
<p>常用参数<br>-f                          #指定要使用的Dockerfile路径<br>–label=[]              #设置镜像使用的元数据；<br>-m                        #设置内存最大值<br>–memory-swap   #设置Swap的最大值为内存+swap，”-1”表示不限swap<br>–no-cache          #创建镜像的过程不使用缓存<br>–pull                   #尝试去更新镜像的新版本<br>-q                       #安静模式，成功后只输出镜像ID<br>–rm                    #设置镜像成功后删除中间容器<br>–ulimit               #Ulimit配置</p>
</blockquote>
<h1 id="查看指定镜像的创建历史"><a href="#查看指定镜像的创建历史" class="headerlink" title="查看指定镜像的创建历史"></a>查看指定镜像的创建历史</h1><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker history</span><br></pre></td></tr></table></figure>
<blockquote>
<p>常用参数<br>-H               #以可读的格式打印镜像大小和日期，默认为true；<br>–no-trunc   #显示完整的提交记录；<br>-q                #仅列出提交记录ID。</p>
</blockquote>
<p>示例</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">[root@docker ~]# docker history newdocker_images:v2</span><br><span class="line">IMAGE             CREATED          CREATED BY                                    SIZE      COMMENT</span><br><span class="line">858cbd9ba687    32 minutes ago   -storage_driver&#x3D;influxdb -storage_driver_d...   0 B       add new images</span><br><span class="line">75f88e3ec333    5 months ago     &#x2F;bin&#x2F;sh -c #(nop)  ENTRYPOINT [&quot;&#x2F;usr&#x2F;bin&#x2F;c...   0 B       </span><br><span class="line">&lt;missing&gt;       5 months ago     &#x2F;bin&#x2F;sh -c #(nop)  EXPOSE 8080&#x2F;tcp              0 B       </span><br><span class="line">&lt;missing&gt;       5 months ago     &#x2F;bin&#x2F;sh -c #(nop) ADD file:e138bb5c0c12107...   26.5 MB   </span><br><span class="line">&lt;missing&gt;       5 months ago     &#x2F;bin&#x2F;sh -c apk --no-cache add ca-certifica...   30.9 MB   </span><br><span class="line">&lt;missing&gt;       5 months ago     &#x2F;bin&#x2F;sh -c #(nop)  ENV GLIBC_VERSION&#x3D;2.23-r3    0 B       </span><br><span class="line">&lt;missing&gt;       5 months ago     &#x2F;bin&#x2F;sh -c #(nop)  MAINTAINER dengnan@goog...   0 B       </span><br><span class="line">&lt;missing&gt;       5 months ago     &#x2F;bin&#x2F;sh -c #(nop)  CMD [&quot;&#x2F;bin&#x2F;sh&quot;]              0 B       </span><br><span class="line">&lt;missing&gt;       5 months ago     &#x2F;bin&#x2F;sh -c #(nop) ADD file:c05a199f603e2a9...   4.82 MB</span><br></pre></td></tr></table></figure>

<h1 id="显示-Docker-系统信息，包括镜像和容器数"><a href="#显示-Docker-系统信息，包括镜像和容器数" class="headerlink" title="显示 Docker 系统信息，包括镜像和容器数"></a>显示 Docker 系统信息，包括镜像和容器数</h1><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker info</span><br></pre></td></tr></table></figure>

<p>示例</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br></pre></td><td class="code"><pre><span class="line">[root@docker ~]# docker info</span><br><span class="line">Containers: 4</span><br><span class="line"> Running: 3</span><br><span class="line"> Paused: 0</span><br><span class="line"> Stopped: 1</span><br><span class="line">Images: 5</span><br><span class="line">Server Version: 1.13.1</span><br><span class="line">Storage Driver: overlay2</span><br><span class="line"> Backing Filesystem: xfs</span><br><span class="line"> Supports d_type: true</span><br><span class="line"> Native Overlay Diff: true</span><br><span class="line">Logging Driver: journald</span><br><span class="line">Cgroup Driver: systemd</span><br><span class="line">Plugins: </span><br><span class="line"> Volume: local</span><br><span class="line"> Network: bridge host macvlan null overlay</span><br><span class="line">Swarm: inactive</span><br><span class="line">Runtimes: docker-runc runc</span><br><span class="line">Default Runtime: docker-runc</span><br><span class="line">Init Binary: &#x2F;usr&#x2F;libexec&#x2F;docker&#x2F;docker-init-current</span><br><span class="line">containerd version:  (expected: aa8187dbd3b7ad67d8e5e3a15115d3eef43a7ed1)</span><br><span class="line">runc version: e9c345b3f906d5dc5e8100b05ce37073a811c74a (expected: 9df8b306d01f59d3a8029be411de015b7304dd8f)</span><br><span class="line">init version: 5b117de7f824f3d3825737cf09581645abbe35d4 (expected: 949e6facb77383876aeff8a6944dde66b3089574)</span><br><span class="line">Security Options:</span><br><span class="line"> seccomp</span><br><span class="line">  WARNING: You&#39;re not using the default seccomp profile</span><br><span class="line">  Profile: &#x2F;etc&#x2F;docker&#x2F;seccomp.json</span><br><span class="line">Kernel Version: 3.10.0-693.el7.x86_64</span><br><span class="line">Operating System: CentOS Linux 7 (Core)</span><br><span class="line">OSType: linux</span><br><span class="line">Architecture: x86_64</span><br><span class="line">Number of Docker Hooks: 3</span><br><span class="line">CPUs: 1</span><br><span class="line">Total Memory: 7.64 GiB</span><br><span class="line">Name: docker</span><br><span class="line">ID: K7N6:CHF5:KAZP:QFDB:VYBP:IWMW:7VMV:L4TB:OJD2:SEZI:YRRR:4TJN</span><br><span class="line">Docker Root Dir: &#x2F;var&#x2F;lib&#x2F;docker</span><br><span class="line">Debug Mode (client): false</span><br><span class="line">Debug Mode (server): false</span><br><span class="line">Registry: https:&#x2F;&#x2F;index.docker.io&#x2F;v1&#x2F;</span><br><span class="line">WARNING: bridge-nf-call-iptables is disabled</span><br><span class="line">WARNING: bridge-nf-call-ip6tables is disabled</span><br><span class="line">Experimental: false</span><br><span class="line">Insecure Registries:</span><br><span class="line"> 127.0.0.0&#x2F;8</span><br><span class="line">Live Restore Enabled: false</span><br><span class="line">Registries: docker.io (secure)</span><br></pre></td></tr></table></figure>

<h1 id="显示-Docker-版本信息"><a href="#显示-Docker-版本信息" class="headerlink" title="显示 Docker 版本信息"></a>显示 Docker 版本信息</h1><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker version</span><br></pre></td></tr></table></figure>

<p>示例</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line">[root@docker ~]# docker version</span><br><span class="line">Client:</span><br><span class="line"> Version:      18.05.0-ce</span><br><span class="line"> API version:  1.37</span><br><span class="line"> Go version:   go1.9.5</span><br><span class="line"> Git commit:   f150324</span><br><span class="line"> Built:        Wed May  9 22:16:25 2018</span><br><span class="line"> OS&#x2F;Arch:      linux&#x2F;amd64</span><br><span class="line"> Experimental: false</span><br><span class="line"> Orchestrator: swarm</span><br><span class="line"></span><br><span class="line">Server:</span><br><span class="line"> Engine:</span><br><span class="line">  Version:      18.05.0-ce</span><br><span class="line">  API version:  1.37 (minimum version 1.12)</span><br><span class="line">  Go version:   go1.9.5</span><br><span class="line">  Git commit:   f150324</span><br><span class="line">  Built:        Wed May  9 22:14:32 2018</span><br><span class="line">  OS&#x2F;Arch:      linux&#x2F;amd64</span><br><span class="line">  Experimental: false</span><br></pre></td></tr></table></figure>


 
      <!-- reward -->
      
      <div id="reword-out">
        <div id="reward-btn">
          打赏
        </div>
      </div>
      
    </div>
    

    <!-- copyright -->
    
    <footer class="article-footer">
       
<div class="share-btn">
      <span class="share-sns share-outer">
        <i class="ri-share-forward-line"></i>
        分享
      </span>
      <div class="share-wrap">
        <i class="arrow"></i>
        <div class="share-icons">
          
          <a class="weibo share-sns" href="javascript:;" data-type="weibo">
            <i class="ri-weibo-fill"></i>
          </a>
          <a class="weixin share-sns wxFab" href="javascript:;" data-type="weixin">
            <i class="ri-wechat-fill"></i>
          </a>
          <a class="qq share-sns" href="javascript:;" data-type="qq">
            <i class="ri-qq-fill"></i>
          </a>
          <a class="douban share-sns" href="javascript:;" data-type="douban">
            <i class="ri-douban-line"></i>
          </a>
          <!-- <a class="qzone share-sns" href="javascript:;" data-type="qzone">
            <i class="icon icon-qzone"></i>
          </a> -->
          
          <a class="facebook share-sns" href="javascript:;" data-type="facebook">
            <i class="ri-facebook-circle-fill"></i>
          </a>
          <a class="twitter share-sns" href="javascript:;" data-type="twitter">
            <i class="ri-twitter-fill"></i>
          </a>
          <a class="google share-sns" href="javascript:;" data-type="google">
            <i class="ri-google-fill"></i>
          </a>
        </div>
      </div>
</div>

<div class="wx-share-modal">
    <a class="modal-close" href="javascript:;"><i class="ri-close-circle-line"></i></a>
    <p>扫一扫，分享到微信</p>
    <div class="wx-qrcode">
      <img src="//api.qrserver.com/v1/create-qr-code/?size=150x150&data=https://dxysun.com/2018/07/10/dockerForCommmand/" alt="微信分享二维码">
    </div>
</div>

<div id="share-mask"></div>  
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/docker/" rel="tag">docker</a></li></ul>

    </footer>
  </div>

   
  <nav class="article-nav">
    
      <a href="/2018/07/10/allKindsOfSort/" class="article-nav-link">
        <strong class="article-nav-caption">上一篇</strong>
        <div class="article-nav-title">
          
            各种排序算法总结及java实现
          
        </div>
      </a>
    
    
      <a href="/2018/07/09/sparkForLocalhostPython/" class="article-nav-link">
        <strong class="article-nav-caption">下一篇</strong>
        <div class="article-nav-title">Spark伪分布式部署并使用pyspark</div>
      </a>
    
  </nav>

  
   
  
</article>

</section>
      <footer class="footer">
  <div class="outer">
    <ul>
      <li>
        Copyrights &copy;
        2015-2024
        <i class="ri-heart-fill heart_icon"></i> dxysun
      </li>
    </ul>
    <ul>
      <li>
        
        
        
        由 <a href="https://hexo.io" target="_blank">Hexo</a> 强力驱动
        <span class="division">|</span>
        主题 - <a href="https://github.com/Shen-Yu/hexo-theme-ayer" target="_blank">Ayer</a>
        
      </li>
    </ul>
    <ul>
      <li>
        
        
        <span>
  <span><i class="ri-user-3-fill"></i>访问人数:<span id="busuanzi_value_site_uv"></span></s>
  <span class="division">|</span>
  <span><i class="ri-eye-fill"></i>浏览次数:<span id="busuanzi_value_page_pv"></span></span>
</span>
        
      </li>
    </ul>
    <ul>
      
        <li>
          <a href="https://beian.miit.gov.cn" target="_black" rel="nofollow">豫ICP备17012675号-1</a>
        </li>
        
    </ul>
    <ul>
      
    </ul>
    <ul>
      <li>
        <!-- cnzz统计 -->
        
      </li>
    </ul>
  </div>
</footer>
      <div class="float_btns">
        <div class="totop" id="totop">
  <i class="ri-arrow-up-line"></i>
</div>

<div class="todark" id="todark">
  <i class="ri-moon-line"></i>
</div>

      </div>
    </main>
    <aside class="sidebar on">
      <button class="navbar-toggle"></button>
<nav class="navbar">
  
  <div class="logo">
    <a href="/"><img src="https://dxysun.com/static/logo.png" alt="迎着朝阳"></a>
  </div>
  
  <ul class="nav nav-main">
    
    <li class="nav-item">
      <a class="nav-item-link" href="/">主页</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/archives">归档</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/categories">分类</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/tags">标签</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/photos">相册</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/friends">友链</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/about">关于我</a>
    </li>
    
  </ul>
</nav>
<nav class="navbar navbar-bottom">
  <ul class="nav">
    <li class="nav-item">
      
      <a class="nav-item-link nav-item-search"  title="搜索">
        <i class="ri-search-line"></i>
      </a>
      
      
      <a class="nav-item-link" target="_blank" href="/atom.xml" title="RSS Feed">
        <i class="ri-rss-line"></i>
      </a>
      
    </li>
  </ul>
</nav>
<div class="search-form-wrap">
  <div class="local-search local-search-plugin">
  <input type="search" id="local-search-input" class="local-search-input" placeholder="Search...">
  <div id="local-search-result" class="local-search-result"></div>
</div>
</div>
    </aside>
    <script>
      if (window.matchMedia("(max-width: 768px)").matches) {
        document.querySelector('.content').classList.remove('on');
        document.querySelector('.sidebar').classList.remove('on');
      }
    </script>
    <div id="mask"></div>

<!-- #reward -->
<div id="reward">
  <span class="close"><i class="ri-close-line"></i></span>
  <p class="reward-p"><i class="ri-cup-line"></i>请我喝杯咖啡吧~</p>
  <div class="reward-box">
    
    <div class="reward-item">
      <img class="reward-img" src="https://tu.dxysun.com/alipay-20201219151322.jpg">
      <span class="reward-type">支付宝</span>
    </div>
    
    
    <div class="reward-item">
      <img class="reward-img" src="https://tu.dxysun.com/weixin-20201219151346.png">
      <span class="reward-type">微信</span>
    </div>
    
  </div>
</div>
    
<script src="/js/jquery-2.0.3.min.js"></script>


<script src="/js/lazyload.min.js"></script>

<!-- Tocbot -->


<script src="/js/tocbot.min.js"></script>

<script>
  tocbot.init({
    tocSelector: '.tocbot',
    contentSelector: '.article-entry',
    headingSelector: 'h1, h2, h3, h4, h5, h6',
    hasInnerContainers: true,
    scrollSmooth: true,
    scrollContainer: 'main',
    positionFixedSelector: '.tocbot',
    positionFixedClass: 'is-position-fixed',
    fixedSidebarOffset: 'auto'
  });
</script>

<script src="https://cdn.jsdelivr.net/npm/jquery-modal@0.9.2/jquery.modal.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/jquery-modal@0.9.2/jquery.modal.min.css">
<script src="https://cdn.jsdelivr.net/npm/justifiedGallery@3.7.0/dist/js/jquery.justifiedGallery.min.js"></script>

<script src="/dist/main.js"></script>

<!-- ImageViewer -->

<!-- Root element of PhotoSwipe. Must have class pswp. -->
<div class="pswp" tabindex="-1" role="dialog" aria-hidden="true">

    <!-- Background of PhotoSwipe. 
         It's a separate element as animating opacity is faster than rgba(). -->
    <div class="pswp__bg"></div>

    <!-- Slides wrapper with overflow:hidden. -->
    <div class="pswp__scroll-wrap">

        <!-- Container that holds slides. 
            PhotoSwipe keeps only 3 of them in the DOM to save memory.
            Don't modify these 3 pswp__item elements, data is added later on. -->
        <div class="pswp__container">
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
        </div>

        <!-- Default (PhotoSwipeUI_Default) interface on top of sliding area. Can be changed. -->
        <div class="pswp__ui pswp__ui--hidden">

            <div class="pswp__top-bar">

                <!--  Controls are self-explanatory. Order can be changed. -->

                <div class="pswp__counter"></div>

                <button class="pswp__button pswp__button--close" title="Close (Esc)"></button>

                <button class="pswp__button pswp__button--share" style="display:none" title="Share"></button>

                <button class="pswp__button pswp__button--fs" title="Toggle fullscreen"></button>

                <button class="pswp__button pswp__button--zoom" title="Zoom in/out"></button>

                <!-- Preloader demo http://codepen.io/dimsemenov/pen/yyBWoR -->
                <!-- element will get class pswp__preloader--active when preloader is running -->
                <div class="pswp__preloader">
                    <div class="pswp__preloader__icn">
                        <div class="pswp__preloader__cut">
                            <div class="pswp__preloader__donut"></div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="pswp__share-modal pswp__share-modal--hidden pswp__single-tap">
                <div class="pswp__share-tooltip"></div>
            </div>

            <button class="pswp__button pswp__button--arrow--left" title="Previous (arrow left)">
            </button>

            <button class="pswp__button pswp__button--arrow--right" title="Next (arrow right)">
            </button>

            <div class="pswp__caption">
                <div class="pswp__caption__center"></div>
            </div>

        </div>

    </div>

</div>

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/default-skin/default-skin.min.css">
<script src="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe-ui-default.min.js"></script>

<script>
    function viewer_init() {
        let pswpElement = document.querySelectorAll('.pswp')[0];
        let $imgArr = document.querySelectorAll(('.article-entry img:not(.reward-img)'))

        $imgArr.forEach(($em, i) => {
            $em.onclick = () => {
                // slider展开状态
                // todo: 这样不好，后面改成状态
                if (document.querySelector('.left-col.show')) return
                let items = []
                $imgArr.forEach(($em2, i2) => {
                    let img = $em2.getAttribute('data-idx', i2)
                    let src = $em2.getAttribute('data-target') || $em2.getAttribute('src')
                    let title = $em2.getAttribute('alt')
                    // 获得原图尺寸
                    const image = new Image()
                    image.src = src
                    items.push({
                        src: src,
                        w: image.width || $em2.width,
                        h: image.height || $em2.height,
                        title: title
                    })
                })
                var gallery = new PhotoSwipe(pswpElement, PhotoSwipeUI_Default, items, {
                    index: parseInt(i)
                });
                gallery.init()
            }
        })
    }
    viewer_init()
</script>

<!-- MathJax -->

<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
      tex2jax: {
          inlineMath: [ ['$','$'], ["\\(","\\)"]  ],
          processEscapes: true,
          skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
      }
  });

  MathJax.Hub.Queue(function() {
      var all = MathJax.Hub.getAllJax(), i;
      for(i=0; i < all.length; i += 1) {
          all[i].SourceElement().parentNode.className += ' has-jax';
      }
  });
</script>

<script src="https://cdn.jsdelivr.net/npm/mathjax@2.7.6/unpacked/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<script>
  var ayerConfig = {
    mathjax: true
  }
</script>

<!-- Katex -->

<!-- busuanzi  -->


<script src="/js/busuanzi-2.3.pure.min.js"></script>


<!-- ClickLove -->

<!-- ClickBoom1 -->

<!-- ClickBoom2 -->

<!-- CodeCopy -->


<link rel="stylesheet" href="/css/clipboard.css">

<script src="https://cdn.jsdelivr.net/npm/clipboard@2/dist/clipboard.min.js"></script>
<script>
  function wait(callback, seconds) {
    var timelag = null;
    timelag = window.setTimeout(callback, seconds);
  }
  !function (e, t, a) {
    var initCopyCode = function(){
      var copyHtml = '';
      copyHtml += '<button class="btn-copy" data-clipboard-snippet="">';
      copyHtml += '<i class="ri-file-copy-2-line"></i><span>COPY</span>';
      copyHtml += '</button>';
      $(".highlight .code pre").before(copyHtml);
      $(".article pre code").before(copyHtml);
      var clipboard = new ClipboardJS('.btn-copy', {
        target: function(trigger) {
          return trigger.nextElementSibling;
        }
      });
      clipboard.on('success', function(e) {
        let $btn = $(e.trigger);
        $btn.addClass('copied');
        let $icon = $($btn.find('i'));
        $icon.removeClass('ri-file-copy-2-line');
        $icon.addClass('ri-checkbox-circle-line');
        let $span = $($btn.find('span'));
        $span[0].innerText = 'COPIED';
        
        wait(function () { // 等待两秒钟后恢复
          $icon.removeClass('ri-checkbox-circle-line');
          $icon.addClass('ri-file-copy-2-line');
          $span[0].innerText = 'COPY';
        }, 2000);
      });
      clipboard.on('error', function(e) {
        e.clearSelection();
        let $btn = $(e.trigger);
        $btn.addClass('copy-failed');
        let $icon = $($btn.find('i'));
        $icon.removeClass('ri-file-copy-2-line');
        $icon.addClass('ri-time-line');
        let $span = $($btn.find('span'));
        $span[0].innerText = 'COPY FAILED';
        
        wait(function () { // 等待两秒钟后恢复
          $icon.removeClass('ri-time-line');
          $icon.addClass('ri-file-copy-2-line');
          $span[0].innerText = 'COPY';
        }, 2000);
      });
    }
    initCopyCode();
  }(window, document);
</script>


<!-- CanvasBackground -->


<script src="/js/dz.js"></script>



    
  </div>
</body>

</html>